//
//  ViewController.swift
//  one
//
//  Created by huangfeng on 2018/4/27.
//  Copyright © 2018年 huangfeng. All rights reserved.
//

import UIKit

class ViewController: UIViewController ,UITableViewDataSource,UITableViewDelegate{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 20
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cellId")
        switch indexPath.row {
        case 0:
            cell?.textLabel?.numberOfLines = 2
            cell?.textLabel?.text = "\(indexPath.row) String Array Dict 元组 KVC \n 运行时简单用法 运行时简单用法"
            
        case 1:
            cell?.textLabel?.text = "\(indexPath.row) uicollectionviewcontroller 使用"
        case 2:
            cell?.textLabel?.text = "\(indexPath.row) function 闭包 block 使用 GCD 使用"
            
        case 3:
            cell?.textLabel?.numberOfLines = 2
            cell?.textLabel?.text = "\(indexPath.row) 便利构造函数 网络简单使用 分便利构造函数 网络简单使用 分类"
        case 4:
            cell?.textLabel?.text = "\(indexPath.row) 私人通讯录"
            
        case 5:
            cell?.textLabel?.text = "\(indexPath.row) 命名空间 反射机制 懒加载"
        case 6:
            cell?.textLabel?.text = "\(indexPath.row) onevcat  swift protocol"
        default:
            cell?.textLabel?.text = "\(indexPath.row)"
        }
        
        return cell!
    }
    
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        switch indexPath.row {
        case 0:
            let tablevc = TableVc()
            self.present(tablevc, animated: true, completion: nil)
        case 1:
            let sb = UIStoryboard(name: "Main", bundle: nil)
            let vc = sb.instantiateViewController(withIdentifier: "CollectionViewController") as! CollectionViewController
            self.present(vc, animated: true, completion: nil)
        case 2:
            let vc = FunctionController()
            self.present(vc, animated: true, completion: nil)
        case 3:
            let vc = ThreeControllerViewController()
            self.present(vc, animated: true, completion: nil)
        case 4:
            let sb = UIStoryboard(name: "Main", bundle: nil)
            let vc = sb.instantiateViewController(withIdentifier: "ListTableViewController") as! ListTableViewController
            let nav = NavController(rootViewController: vc)
            self.present(nav, animated: true, completion: nil)
        case 5:
            let vc = LazyController()
            self.present(vc, animated: true, completion: nil)
        case 6:
            let vc = ProtocolController()
            self.present(vc, animated: true, completion: nil)
        default:
            print("")
        }
    }
    
    
//    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
//        let hview = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: 30))
//        hview.backgroundColor = UIColor.red
//
//        let butn = UIButton(frame: CGRect(x: 0, y: 10, width: 50, height: 20))
//        butn.setTitle("返回", for: .normal)
//        butn.backgroundColor = UIColor.orange
//        butn.setTitleColor(UIColor.black, for: .normal)
//        hview .addSubview(butn)
//        butn.addTarget(self, action: #selector(back), for: .touchUpInside)
//        return hview
//    }
    
    
    
//    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
//        return 30
//    }
    
    @objc func back() {
        self.dismiss(animated: true) {
            
        }
    }
    

    
    // MARK: 视图生命周期
    // MARK: 视图加载完成
    
    
    /// option + cmd + / 增加文档注释
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tableview = UITableView(frame: view.bounds, style: .plain)
        view.addSubview(tableview)
        tableview.dataSource = self
        tableview.delegate = self
        tableview.register(UITableViewCell.self, forCellReuseIdentifier: "cellId")
    }
    
    


    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

